package com.chinatsp.onlineapp.ui.news;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chinatsp.onlineapp.R;
import com.chinatsp.onlineapp.bean.NewsDetail;
import com.chinatsp.onlineapp.utils.Utils;


import java.util.List;

/**
 * Created by cbb on 2016/10/18.
 * 新闻标题 适配
 */
public class NewsItemAdapter extends BaseAdapter {
    //List<NewsTitle> titleList;//新闻标题
    List<NewsDetail> detailList;//新闻 详细
    LayoutInflater inflater;
    public NewsItemAdapter(Context context){
        this.inflater=LayoutInflater.from(context);
    }



    public void setDetailList(List<NewsDetail> detailList) {
        this.detailList = detailList;
    }



    @Override
    public int getCount() {
        return detailList.size();
    }

    @Override
    public Object getItem(int position) {
        return detailList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            holder=new ViewHolder();
            convertView=inflater.inflate(R.layout.item_title_news,null);
            holder.first= (TextView) convertView.findViewById(R.id.tv_title_first);
            holder.title= (TextView) convertView.findViewById(R.id.tv_title_name);
            holder.content= (TextView) convertView.findViewById(R.id.tv_title_content);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.first.setText(detailList.get(position).news_title.substring(0,1));
        holder.title.setText(detailList.get(position).news_title);
        holder.content.setText(Utils.getNewsContent(detailList.get(position).news_content));
        return convertView;
    }
    static class ViewHolder{
        TextView first;//首字母
        TextView title;//标题
        TextView content;//内容
    }
}
